<!DOCTYPE html>
<html>
<head>
    <title>银行信息</title>
    <include file='public/head'>
  <style>
    .layui-legend-size{font-size:14px !important;}
    .layui-nopadding{padding:0 !important;}
    .layui-overflow{overflow:auto;}
    .layui-nomargin{margin: 0 !important;}
    .layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
    .layui-input{height:30px !important; }
    .layui-form-search-item .layui-inline{margin-bottom: 5px;} 
    .layui-form-search-item label{margin-left: 15px;}
    .layui-table-page {padding: 7px 0px 0px;}
    .layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
  </style>
</head>
<div class="layui-tab " lay-filter="demo-tab" class="js-check-wrap">
  <!-- 顶部导航菜单开始 -->
  <div class="layui-tab-nav" >
        <ul class="layui-tab-title">
            {:getNav('fund','admin_index/banklist')};
        </ul>
    </div>
    <!-- 顶部导航菜单结束 -->
    <fieldset class="layui-elem-field layui-field-title layui-field-padding">
        <legend class="layui-legend-size">搜索</legend>
        <form class="layui-form table-bar" action="{:cmf_plugin_url('Fund://admin_index/banklist')}" lay-filter="form-bar" method="post">
          <div class="layui-form-search-item">
            <div class="layui-inline ">
                <div class="layui-input-inline " style="width: 100px;">
                    <select name="types">
                        <option value="1" <?php if(isset($search['types']) && $search['types']==1){echo 'selected';} ?>>银行</option>
                        <option value="2" <?php if(isset($search['types']) && $search['types']==2){echo 'selected';} ?>>card_bin</option>
                        <option value="3" <?php if(isset($search['types']) && $search['types']==3){echo 'selected';} ?>>卡种</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline ">
                <div class="layui-input-inline " style="width: 100px;">
                    <input type="text" name="category" autocomplete="off" class="layui-input" value="{$search['category']|default=''}">
                </div>
            </div>
            <button type="submit" class="layui-btn layui-btn-sm layui-btn-primary " style="font-weight:800;" lay-submit="" lay-filter="demo2"><i class="layui-icon ">&#xe615;</i>搜索</button>
          </div>
        </form>
    </fieldset>
    <div class="layui-card">
        <div class="layui-card-header layui-bg-gray layui-bottom">
            <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger" onclick="allDelete()"><i class="layui-icon">&#xe640;</i>批量删除</a>
            <a class="layui-btn layui-btn-xs layui-btn-default" href="javascript:;" onclick="addbank()">添加银行</a>
        </div>
        <div class="layui-card-body layui-nopadding">
            <form method="post" id="f">
                <table  class="layui-table layui-nomargin" >
                    <thead>
                        <tr>
                            <th width='20px'>
                                <input type='checkbox' id='check-box-all' class='layui-form-checkbox'>
                            </th>
                            <th>ID</th>
                            <th>银行LOGO</th>
                            <th>bin(卡号前2-8位))</th>
                            <th>银行</th>
                            <th>银行卡类</th>
                            <th>银行卡种</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <volist name="data" id="vo">
                            <tr>
                                <th>
                                    <input type="checkbox" class='check-box' name='id[]' value='{$vo.id}'>
                                </th>
                                <td>{$vo['id']}</td>
                                <td>
                                    <if condition="$vo['thumb']=='/plugins/fund/view/public'">
                                    <p>暂无图片</p>
                                    <else />
                                    <img src="__ROOT__{$vo['thumb']}" style='height:60px;'>
                                    </if>
                                </td>
                                <td>{$vo['card_bin']}</td>
                                <td>{$vo['bank']}</td>
                                <td>{$vo['card_type']}</td>
                                <td>{$vo['desc']}</td>
                                <td>
                                    <switch name="$vo['status']">
                                      <case value="0"><p >开</p></case>
                                      <case value="1"><p>关</p></case>
                                    </switch>
                                </td>
                                <td>
                                    <div class="layui-btn-group">
                                        <button type='button' class='layui-btn layui-btn-xs layui-btn-primary update-btn' onclick="edit({$vo['id']})" style='font-weight:800 ;' data-id='{$vo.id}' title='编辑'><i class='layui-icon'>&#xe642;</i></button>
                                        <!-- <a href="{:cmf_plugin_url('Goods://admin_index/editGoods')}?id={$vo.id}" class='layui-btn layui-btn-xs layui-btn-primary update-btn' title='编辑'><i class='layui-icon'>&#xe642;</i></a> -->
                                        <button type='button' class='layui-btn layui-btn-xs layui-btn-primary delete-btn' style='font-weight:800 ;' data-id='{$vo.id}' title='删除'><i class='layui-icon'>&#xe640;</i></button>
                                    </div>
                                </td>
                            </tr>
                        </volist>
                    </tbody>
                </table>
            </form>
            <div class="layui-table-page">
                <div id="layui-table-page1">
                    <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
                        {$page|default=''}
                    </div>
                </div>
            </div>
        </div>
    </div>
<!-- 添加银行 -->
<div id="write" style="display: none">
    <form method="post" enctype="multipart/form-data" id="addbank" action="{:cmf_plugin_url('Fund://admin_index/addbank')}" style="width: 90%;margin-left: 5%;margin-top: 30px">
        <table class="layui-table layui-nomargin">
            <tbody>
                <tr>
                    <td>银行</td>
                    <td><input type="text"  class="layui-input" value="" name="bank"></td>
                </tr>
                <tr>
                    <td>描述</td>
                    <td><input type="text" class="layui-input" value="" name="desc"></td>
                </tr>
                <tr>
                    <td>银行LOGO</td>
                    <td>
                        <input type="hidden" class="tupain" name="thumb" value="">
                        <label>
                            <img src="__PLUGIN_TMPL__/public/assets/images/timg.png"  class="logoimg" style="height: 100px;">
                            <input type="file" id="front" accept="image/png,image/jpeg,image/jpg" ref="inputer" onchange="photo(this)" style="position:absolute;opacity:0;">
                        </label>       
                    </td>
                </tr>
                <tr>
                   <td>是否显示</td>
                   <td>
                        <div>
                             <input type="radio" name="powerExp" class="powerExp on" value="0" />
                             <label for="powerExp_on">开</label>
                             <input type="radio" name="powerExp" style="margin-left: 20px" class="powerExp off" value="1" />
                             <label for="powerExp_off">关</label>
                        </div>
                        <!-- <div class="checkbox">
                            <label>
                                <input type="radio" name="powerExp" class="powerExp on" value="0" />开
                                <input type="radio" name="powerExp" style="margin-left: 20px" class="powerExp off" value="1" />关
                            </label>
                        </div> -->
                   </td>
                </tr>
           </tbody>
        </table>
    </form>
</div>  
<!-- 修改银行 -->
 <div id="write2"  style="display: none" >
        <form method="post" enctype="multipart/form-data" id="editbank" action="{:cmf_plugin_url('Fund://admin_index/upbank')}" style="width: 90%;margin-left: 5%;margin-top: 30px">
          <input name="id" id="id" type="hidden" value="">
            <table class="layui-table layui-nomargin">
               <tbody>
                 <tr>
                   <td align="center">银行</td>
                   <td align="center"><input type="text" id="bank" class="layui-input" value="" name="bank"></td>
                 </tr>
                 <tr>
                   <td align="center">描述</td>
                   <td align="center"><input type="text" id="desc" class="layui-input" value="" name="desc"></td>
                 </tr>
                 <tr>
                   <td align="center">银行LOGO</td>
                   <td align="center">
                    <input type="hidden" id="tu" class="tupain" name="thumb" value="">
                    <label>
                      <img src="__PLUGIN_TMPL__/public/assets/images/timg.png" id="img" class="logoimg" style="height: 100px;">
                      <input type="file" id="front" accept="image/png,image/jpeg,image/jpg" ref="inputer" onchange="photo(this)" style="position:absolute;opacity:0;">
                    </label>       
                   </td>
                 </tr>
                 <tr>
                   <td align="center">是否显示</td>
                   <td align="center">
                       <div class="p10">
                             <input class="powerExp on" id="radio0" name="powerExp" type="radio" value="0" />
                             <label for="powerExp_on">开</label>
                             <input style="margin-left: 20px" id="radio1" class="powerExp off" name="powerExp" type="radio" value="1" />
                             <label for="powerExp_off">关</label>
                        </div>
                   </td>
                 </tr>
               </tbody>
            </table>
        </form>
    </div>
</div>
<include file="public/scripts"/>
<script type="text/javascript">
//全选/取消
$('#check-box-all').on('click',function(){
    $('.check-box').prop('checked',$('#check-box-all').prop('checked'));
});
function addbank(){
    layer.open({
        title:"添加银行",
        type:1,
        area:['700px','600px'],
        btn:['确认','返回'],
        content:$("#write"),
        yes:function(){
            // console.log($('#addbank').serialize());
            $.ajax({
                url:"{:cmf_plugin_url('Fund://admin_index/addbank')}",
                type:'post',
                data: $('#addbank').serialize(),
                success: function(data){
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:1,time:1500},function(){
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg,{icon:2,time:1500});
                    }
                },
                error:function(){
                    layer.msg('系统错误',{icon:2,time:1500});
                }
            })
        },
        end: function () {
            $("#write").css('display','none');
        }
    })
}
//上传图片
function photo(_this){
  var data = $(_this).val();
  let file = _this.files[0];
  data = new FormData();
  data.append('photo', file);
  $.ajax({
        type: "post",
        url: "{:cmf_plugin_url('Fund://admin_index/addphoto')}",
        data: data,
        dataType: "json",
        processData: false,
        contentType: false,
        cache: false,
        success: function (data) {
            $(".tupain").val(data.data);
            $('.logoimg').attr('src',"__ROOT__"+data.data);
        },
        error: function (data) {
          alert("图片上传失败");
        }
      });
}
 function edit(id){
    $("#id").val(id);
    $.ajax({
        type:"get",// get或者post
        url:"{:cmf_plugin_url('Fund://admin_index/fund_bank')}",// 请求的url地
        data:{id},
        dataType:"json",
        success:function(data){
            console.log(data);
            $("#bank").val(data['bank']);
            $("#desc").val(data['desc']);
            $("#tu").val(data['thumb']);
            $("#img").attr('src',"__ROOT__"+data['thumb']);
            $("#radio"+data['status']).attr('checked','checked');
        }
    });
    layer.open({
        title:"修改银行",
        type:1,
        btn:['确认','返回'],
        area:['700px','600px'],
        content:$("#write2"),
        yes: function(){
            $.ajax({
                url:"{:cmf_plugin_url('Fund://admin_index/upbank')}",
                data: $('#editbank').serialize(),
                type: 'post',
                success:function(data){
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:1,time:1500},function(){
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg,{icon:2,time:1500});
                    }
                },
                error:function(){
                    layer.msg('系统错误',{icon:2,time:1500});
                }
            })
        },
        end: function () {
            $("#write2").css('display','none');
        }
    })
 }
//删除
$('.delete-btn').on('click',function(){
    var text = "确定要删除该数据？";
    let id = $(this).data('id');
    let url = "{:cmf_plugin_url('Fund://admin_index/delbank')}";
    layer.confirm(text, {icon: 3, title:'提示', btn: ['删除','取消']}, function(index,layero){
        $.ajax({
            url:url,
            type:"post",
            data:{
                id:id
            },
            success:function(data){
                if (data.code == 1) {
                    layer.msg(data.msg,{icon:1,time:1500},function(){
                        window.location.reload();
                    });
                } else {
                    layer.msg(data.msg,{icon:2,time:1500});
                }
            },
            error:function(){
                layer.msg('系统错误',{icon:2,time:1500});
            }
        })
    },function(index){
        // alert('取消');
    });
});
//批量删除
function allDelete()
{
    var text = "确定要删除该数据？";
    let data = $('#f').serialize();
    let url = "{:cmf_plugin_url('Fund://admin_index/delAccount')}";
    layer.confirm(text, {icon: 3, title:'提示', btn: ['删除','取消']}, function(index,layero){
        $.ajax({
            url:url,
            type:"post",
            data:data,
            success:function(data){
                if (data.code == 1) {
                    layer.msg(data.msg,{icon:1,time:1500},function(){
                        window.location.reload();
                    });
                } else {
                    layer.msg(data.msg,{icon:2,time:1500});
                }
            },
            error:function(){
                layer.msg('系统错误',{icon:2,time:1500});
            }
        })
    },function(index){
        // alert('取消');
    });
}
</script>
</body>
</html> 
